<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style type="text/css">
        .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            黑名单
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">物料号</div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="选择物料" id="mrlCode" value="" onclick="getIdSelector();" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectMrl()"></i>
                    </div>
                </li>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料名称</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">批次号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入批次号" id="lotCode" value="" onclick="getIdSelector();" />
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">精准关键件码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入精准关键件码" id="ktpartCode" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">总成码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请输入总成码" id="zcCode" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">状态</div>
                    <select id="isActive">
                        <option value=''>--请选择--</option>
                        <option value='0'>启用</option>
                        <option value='1'>禁用</option>
                  </select>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info" style="margin-left:5%;width:40%" onclick="add()">新增</div>
        <div class="aui-btn aui-btn-info" style="margin-left:5%;width:40%" onclick="doSearch()">查询</div>

        <div id="divhtml" style="display: block;width:100%;height: 490px;overflow-y: scroll;"></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //初始化查询仓库下拉框
    apiready = function() {

        //查询
        doSearch();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        $("#" + el.id).select();
    }

    //选择物料
    function goSelectMrl() {
        api.openWin({
            name: 'usmSelectMrl',
            url: 'usmSelectMrl.html',
            pageParam: {
                name: "qcMrlBlacklist",
            }
        });
    }

    //物料选择后回调函数
    function setMrl(sysid, code, name) {
        $("#mrlCode").val(code);
        $("#mrlName").val(name);

    }

    //查询
    function doSearch() {
        //物料号
        var mrlCode = $("#mrlCode").val();
        //批次号
        var lotCode = $("#lotCode").val();
        //精准关键件码
        var ktpartCode = $("#ktpartCode").val();
        //总成码
        var zcCode = $("#zcCode").val();
        //状态
        var isActive = $("#isActive").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSearchBlacklist";
        var data = {
            values: {
                mrlCode: mrlCode,
                lotCode: lotCode,
                ktpartCode: ktpartCode,
                zcCode: zcCode,
                isActive: isActive,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    var active = "";
                    for (var i = 0; i < list.length; i++) {
                        if(list[i].isActive == "0"){
                            active = "启用";
                        }else{
                            active = "禁用";
                        }
                        //序号
                        html += "<div class='class-seqno'>";
                        html += "<span>" + (i + 1) + "</span>";
                        html += "</div>";
                        //表格
                        html += "<div style='margin-left:10px;margin-right:15px;'>";
                        html += "<table class='class-table'>";
                        html += "<tr>";
                        html += "<td class='class-td' style='width:60%'>物料编码:" + list[i].mrlCode + "</td>";
                        html += "<td class='class-td' style='width:40%'>物料名称:" + list[i].mrlName + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td' >批次号:" + list[i].lotCode + "</td>";
                        html += "<td class='class-td'>精准关键件码:" + list[i].ktpartCode + "</td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td' >总成码:" + list[i].zcCode + "</td>";
                        html += "<td class='class-td'><div class='aui-btn aui-btn-info' onclick='changeType(\"" + list[i].sysid + "\",\"" + list[i].isActive + "\")'>启用/禁用</div></td>";
                        html += "</tr>";
                        html += "<tr>";
                        html += "<td class='class-td' >状态:" + active + "</td>";
                        html += "</tr>";
                        html += "</table>";
                        html += "<hr class='class-hr' />";
                        html += "</div>";
                    }
                    $api.html($api.byId("divhtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //状态修改
    function changeType(sysid, isActive) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/changeTypeBlacklist";
        var data = {
            values: {
                sysid: sysid,
                isActive: isActive,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    api.toast({
                        msg: "状态修改成功！"
                    });
                    doSearch();
                }else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //新增
    function add() {
        //物料号
        var mrlCode = $("#mrlCode").val();
        //物料号
        var mrlName = $("#mrlName").val();
        //批次号
        var lotCode = $("#lotCode").val();
        //精准关键件码
        var ktpartCode = $("#ktpartCode").val();
        //总成码
        var zcCode = $("#zcCode").val();
        //状态
        var isActive = $("#isActive").val();

        //物料号非空校验
        if (mrlCode == "" || mrlCode == null || mrlCode == undefined) {
            api.toast({
                msg: '请选择物料！',
                duration: 3000
            });
            return;
        }

        //状态非空校验
        if (isActive == "" || isActive == null || isActive == undefined) {
            api.toast({
                msg: '请选择状态！',
                duration: 3000
            });
            return;
        }

        //批次号/总成码/精准关键件码校验
        if ((lotCode == "" || lotCode == null || lotCode == undefined) && (ktpartCode == "" || ktpartCode == null || ktpartCode == undefined)
            && (zcCode == "" || zcCode == null || zcCode == undefined)) {
            api.toast({
                msg: '批次号/总成码/精准关键件码至少输入一个！',
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/addBlacklist";
        var data = {
            values: {
                mrlCode: mrlCode,
                mrlName: mrlName,
                lotCode: lotCode,
                ktpartCode: ktpartCode,
                zcCode: zcCode,
                isActive: isActive,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    api.toast({
                        msg: "新增成功！"
                    });
                    //清空数据
                    $("#mrlCode").val("");
                    $("#mrlName").val("");
                    $("#lotCode").val("");
                    $("#ktpartCode").val("");
                    $("#zcCode").val("");
                    $("#isActive").val("");

                    doSearch();
                }else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
